"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocketConnectionManager = void 0;
class SocketConnectionManager {
    constructor() {
        this.socketConnList = [];
        // public sendMsgToUser(user:UserModel, totalPack){
        //     let conn: SocketConnection = SocketConnectionManager.instance.getSocketConnectionByUser(user.userId, user.isPlayer)
        //     if (conn) {
        //         conn.sendMsgToClient(totalPack);
        //     }
        // }
        // public deleteConnectionUser(user:UserModel){
        //     let conn: SocketConnection = SocketConnectionManager.instance.getSocketConnectionByUser(user.userId, user.isPlayer)
        //     if (conn) {
        //         conn.user = null;
        //     }
        // }
    }
    init() {
        this.socketConnList = [];
    }
    /*
   增加客户端socket连接
    */
    addSocketConnection(conn) {
        this.socketConnList.push(conn);
    }
    getSocketConnection(id) {
        for (let i = 0; i < this.socketConnList.length; i++) {
            let conn = this.socketConnList[i];
            if (conn.id == id) {
                return conn;
            }
        }
    }
    getSocketConnectionByUser(account, socketConn) {
        let result;
        for (let i = 0; i < this.socketConnList.length; i++) {
            let conn = this.socketConnList[i];
            if (conn.id != socketConn.id) {
                if (!conn.isClosing && conn.user && conn.user.userName == account) {
                    result = conn;
                    break;
                }
            }
        }
        return result;
    }
    /*
    删除客户端socket连接
     */
    removeSocketConnection(removeOne) {
        if (!removeOne) {
            return;
        }
        for (let i = 0; i < this.socketConnList.length; i++) {
            let conn = this.socketConnList[i];
            if (conn.id == removeOne.id) {
                this.socketConnList.splice(i, 1);
                return;
            }
        }
    }
}
exports.SocketConnectionManager = SocketConnectionManager;
SocketConnectionManager.instance = new SocketConnectionManager();
